<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }

        #box {
            width: 100px;
            height: 100px;
            background: plum;
            position: absolute;
        }
    </style>
</head>
<body>
<div id="box"></div>
</body>
<script>
    class Tuozhuai {
        constructor(box) {
            this.oBox = document.getElementById(box);
            this.x = 0;
            this.y = 0;
            this.move();
        }

        move() {
            var _this = this
            this.oBox.onmousedown = function (ev) {
                var ev = ev || event;
                var oBorder = document.createElement("div");
                oBorder.style.width = "94px";
                oBorder.style.height = "94px";
                oBorder.style.border = "dashed 3px purple";
                oBorder.style.position = "absolute";
                oBorder.style.left = _this.x + "px";
                oBorder.style.top = _this.y + "px";
                document.body.appendChild(oBorder);
                var left = ev.clientX - _this.oBox.offsetLeft;
                var top = ev.clientY - _this.oBox.offsetTop;
                document.onmousemove = function (ev) {
                    var ev = ev || event;
                    _this.x = ev.clientX - left;
                    _this.y = ev.clientY - top;
                    oBorder.style.left = _this.x + "px";
                    oBorder.style.top = _this.y + "px";

                };
                document.onmouseup = function () {
                    _this.oBox.style.left = _this.x + "px";
                    _this.oBox.style.top = _this.y + "px";
                    document.body.removeChild(oBorder);
                    document.onmousemove = null;
                    document.onmouseup = null;
                };
                return false;
            };
        }
    }

    window.onload = function () {
        new Tuozhuai("box")
    };
</script>
<html>